package com.apinji.common.plugin;

import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static sun.plugin.cache.FileVersion.regEx;

/**
 * Created by 轩辕夏夏 on 2017/7/3.
 */
public final class StrUtils {
    private StrUtils() {}

    /**
     * 判定一个字符串是否为空
     * 为空的条件是：null 或者 ""
     *
     * @param str
     * @return
     */
    public static boolean isEmpty(String str) {
        return null == str || str.equals("");
    }

    /**
     *
     * @return
     */
    public static String uuid(){
        return UUID.randomUUID().toString().replace("-","");
    }


    /**
     * 判断字符串是否符合UUID格式
     * @param uuidStr
     * @return
     */
    public static boolean checkUuid(String uuidStr) {
        String regEx = "[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}";
        Pattern p= Pattern.compile(regEx);
        Matcher m=p.matcher(uuidStr);
        boolean rs = m.matches();
        return rs;
    }
}
